package com.xht.controller;

import com.xht.domain.ResponseResult;
import com.xht.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UploadController {

    @Autowired
    private UploadService uploadService;

    //上传图片
    @PostMapping("/upload")
    public ResponseResult upload(@RequestParam("img") MultipartFile file) {

        try {
            return uploadService.uploadImg(file);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("文件上传 上传失败了 !!!");
        }
    }

    //上传视频
    @PostMapping("/upload/video")
    public ResponseResult uploadVideo(@RequestParam("file") MultipartFile file) {
        try {
            return uploadService.uploadVideo(file);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("视频上传 上传失败了 !!!");
        }
    }
}
